/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(function() {
    $( "#pn1" ).draggable();
    $( "#pn2" ).draggable();
    $( "#pn3" ).draggable();
    $( "#pn4" ).draggable();
    $( "#pn5" ).draggable();
    $( "#pn6" ).draggable();
    $( "#pn7" ).draggable();
    $( "#pn8" ).draggable();
    $( "#pb1" ).draggable();
    $( "#pb2" ).draggable();
    $( "#pb3" ).draggable();
    $( "#pb4" ).draggable();
    $( "#pb5" ).draggable();
    $( "#pb6" ).draggable();
    $( "#pb7" ).draggable();
    $( "#pb8" ).draggable();
    $( "#tn1" ).draggable();
    $( "#tn2" ).draggable();
    $( "#fn1" ).draggable();
    $( "#cn1" ).draggable();
    $( "#fn2" ).draggable();
    $( "#cn2" ).draggable();
    $( "#rn" ).draggable();
    $( "#dn" ).draggable();
    $( "#tb1" ).draggable();
    $( "#tb2" ).draggable();
    $( "#fb1" ).draggable();
    $( "#cb1" ).draggable();
    $( "#fb2" ).draggable();
    $( "#cb2" ).draggable();
    $( "#rb" ).draggable();
    $( "#db" ).draggable();

    $("td").each(function() {
        $(this).droppable({
            drop: handlePieceDrop
        });
    }
);
     $(document).ready(boucleEchec());
}
   )


 function handlePieceDrop( event, ui ){
     stockerDeplacement(ui.draggable.appendTo($(this)).attr('id'),$(this).attr('id'),'coco', '9');
     $(this).html('');
     ui.draggable.appendTo($(this)).css({left : '0px' , top : '0px'});
     
     
 }

 function stockerDeplacement(pdep,parr,pcouleur,pnumero){
//     var pdep = $("#dep").val();
//     var parr = $("#arr").val();
//     var pcouleur = $("#couleur").val();
//     var pnumero = $("#numero").val();

     $.ajax({url: "jsp/Deplacements.jsp",
                    type: 'POST',
                    //data: 'dep='+pdep,
                    data: {dep: pdep,
                            arr: parr,
                            couleur: pcouleur,
                            numero: pnumero
                        },
                    error : function(){
                        //alert("erreur a l'envoie de la requette ajax par jquery");
                        //document.getElementById("heure").innerHTML +="erreur";
                    },
                    success: function(xml){
                        //alert("succes");
                   }
                });
                return false;
 }

function showlogs(){
    $("#logdiv").show();
}

function showman(){
    $("#manuel").show();
}